//
//  YKPhotoView.m
//  youkan
//
//  Created by 吴高烽 on 16/3/14.
//  Copyright © 2016年 Honsintech. All rights reserved.
//

#import "YKPhotoView.h"
#import "UIImageView+WebCache.h"
#import "YKPhoto.h"
@interface YKPhotoView()
@property (nonatomic, weak) UIImageView *gifView;
@end
@implementation YKPhotoView
-(instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
        self.contentMode=UIViewContentModeScaleAspectFill;
        self.userInteractionEnabled =YES;
        self.clipsToBounds =YES;
        UIImageView *gifView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"timeline_image_gif"]];
        [self addSubview:gifView];
        _gifView =gifView;
    }
    return self;
}
-(void)setPhoto:(YKPhoto *)photo{
    _photo =photo;
    [self sd_setImageWithURL:photo.thumbnail_pic placeholderImage:[UIImage imageNamed:@"timeline_image_placeholder"]];
    NSString *strUrl=photo.thumbnail_pic.absoluteString;
//    YKLog(@"absoluteString==%@",strUrl);
    if (self.height>self.width*3) {
          YKLog(@"长图==%@",strUrl);
    }
    if ([strUrl hasSuffix:@".gif"]) {
        self.gifView.hidden =NO;
    }else{
        self.gifView.hidden =YES;
    }
}
-(void)layoutSubviews{
    [super layoutSubviews];
    self.gifView.x=self.width-self.gifView.width;
    self.gifView.y =self.height -self.gifView.height;
}
@end
